﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Maticsoft.Common
{
    public class AppCommon
    {
        private static AppCommon _instance = null;
        private string logDirectory;
        private Logger logger;
        public readonly string SiteRoot = "http://nhbcyz123.w48.mc-test.com/";
        public static AppCommon Instance
        {
            get
            {
                if (_instance == null)
                { _instance = new AppCommon(); }
                return _instance;
            }
        }

        private AppCommon()
        {
        }
        private HashSet<string> cacheFreeOpenids = new HashSet<string>();

        public HashSet<string> CacheFreeOpenids
        {
            get { return cacheFreeOpenids; }
        }
        private object theobj = new object();
        public void AddCache(string openid)
        {
            lock (theobj)
            {
                cacheFreeOpenids.Add(openid);
            }
        }
        public void DeleteCache(string openid)
        {
            lock (theobj)
            {
                cacheFreeOpenids.Remove(openid);
            }
        }
        ~AppCommon()
        {
            if (logger != null)
            {
                logger.Dispose();
            }
        }



        #region Properties



        public string LogDirectory
        {
            get { return logDirectory; }
            set { logDirectory = value; }
        }

        public Logger LoggerHandler
        {
            get
            {
                if (logger == null)
                {
                    logger = new Logger(logDirectory + "log.txt");
                }
                return logger;
            }
        }


        private string app_datadir;

        public string App_DataDir
        {
            get { return app_datadir; }
            set { app_datadir = value; }
        }

        #endregion

    }
}
